package com.ysd.controller;

import com.alibaba.fastjson.JSON;
import com.ysd.dao.ClassinfoMapper;
import com.ysd.entity.ClassInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ClassInfoController
 * @Description TODO
 * @Author lvzhenzhen
 * @Date 2021/11/18 17:39
 */
@Controller
@RequestMapping("/class")
public class ClassInfoController {
    @Resource
    ClassinfoMapper classinfoMapper;

    @RequestMapping(value = "/chaxun", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String chaxun() {
        List<ClassInfo> list = classinfoMapper.selectAll();
        return JSON.toJSONString(list);
    }
    @RequestMapping(value = "/add", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String add(){
        ClassInfo classInfo = new ClassInfo();
        classInfo.setClassname("测试");
        Map<String,Object> guige = new HashMap<>();
        guige.put("color","red");
        guige.put("size",64);

        classInfo.setGuige(guige);
        int n = classinfoMapper.add(classInfo);
        return "";
    }

    @RequestMapping(value = "/test/{user}", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String test(@PathVariable String user){

        return user;
    }
}
